package com.huadragon.marathonservice.service.impl;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huadragon.marathondao.dao.inter.IAccountInfoDao;
import com.huadragon.marathondao.dao.inter.IMenuInfoDao;
import com.huadragon.marathonentity.servicedomain.AccountInfoDomain;
import com.huadragon.marathonentity.servicedomain.MenuInfoDomain;
import com.huadragon.marathonservice.common.ServersManager;
import com.huadragon.marathonservice.service.inter.IAccountInfoService;
import com.huadragon.marathonservice.service.inter.IMenuInfoService;


@Service
public class MenuInfoServiceImpl extends ServersManager<MenuInfoDomain, IMenuInfoDao> implements
IMenuInfoService{
	@Autowired
	private IMenuInfoDao dao;
	
	@Override
	public List<MenuInfoDomain> getMenuListByUserID(int userID) {
		/*String key=RedissCacheKey.Menu_Auth+accountId;
		List<MenuInfoDomain> result=redisService.get(key, List.class);
		if (result==null||result.size()==0) {
			List<MenuInfoDomain> list = getReadOnlySqlSessionUtil()
					.selectList(
							"IMenuInfoDao.getMenuListByUserID",
							accountId);
			redisService.set(key, list);
			return list;*/
		return dao.getMenuListByUserID(userID);
	}

	@Override
	public boolean checkHasAuth(int userID,int menuID) {
		List<MenuInfoDomain> data=dao.getMenuListByUserID(userID);
		if (data!=null&&data.size()>0) {
			for (MenuInfoDomain menuEntity : data) {
				if (menuID==menuEntity.getId()) {
					return true;
				}
			}
		}

		return false;
	}
	/**
	 * 根据AuthCode判断用户是否有该权限
	 * 2015年12月2日14:42:12
	 * 茹化肖
	 */
	@Override
	public boolean checkHasAuthByCode(int userID,String authCode) {
		List<MenuInfoDomain> data=dao.getMenuListByUserID(userID);
		if (data!=null&&data.size()>0) {
			for (MenuInfoDomain menuEntity : data) {
				if (authCode.equals(menuEntity.getAuthCode())) {
					return true;
				}
			}
		}
		return false;
	}
	@Override
	public List<MenuInfoDomain> getAuthSettingList(int userID) {
		return dao.getAuthSettingList(userID);
	}

	@Override
	public List<MenuInfoDomain> getMenuListByRoleID(int roleID) {
		return dao.getMenuListByRoleID(roleID);
	}
	
	@Override
	public List<MenuInfoDomain> getMenuResourceByUserID(int userID) {
		return dao.getMenuResourceByUserID(userID);
	}

	@Override
	public List<MenuInfoDomain> getListMenuByParId(int parId) {
		return dao.getListMenuByParId(parId);
	}

	@Override
	public MenuInfoDomain getMenuById(int id) {
		return dao.getMenuById(id);
	}

	@Override
	public boolean addMenu(MenuInfoDomain req) {
		return dao.addMenu(req);
	}



}
